#version 400

uniform mat4 Modelview;
uniform mat3 NormalMatrix;

layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

in vec3 tePosition[3];
in vec3 tePatchDistance[3];
in vec3 teLightDir[3];
in vec3 teNormal[3];

in vec3 teWireframeColor[3];

out vec3 gFacetNormal;
out vec3 gPosition;
out vec3 gPatchDistance;
out vec3 gTriDistance;
out vec3 gLightDir;
out vec3 gVertexNormal;
out vec3 gWireframeColor;

in vec3 color[];
out vec3 colorGeom;

void main()
{
	colorGeom = color[0];
    vec3 A = tePosition[2] - tePosition[0];
    vec3 B = tePosition[1] - tePosition[0];
    gFacetNormal = normalize(cross(A, B));
    
	gWireframeColor = teWireframeColor[0];
    gPatchDistance = tePatchDistance[0];
    gTriDistance = vec3(1, 0, 0);
    gl_Position = gl_in[0].gl_Position; 
	gLightDir = teLightDir[0];
	gVertexNormal = teNormal[0];
	gPosition = tePosition[0];
	EmitVertex();

	gWireframeColor = teWireframeColor[1];
    gPatchDistance = tePatchDistance[1];
    gTriDistance = vec3(0, 1, 0);
    gl_Position = gl_in[1].gl_Position;
	gLightDir = teLightDir[1];
	gVertexNormal = teNormal[1];
	gPosition = tePosition[1];
	EmitVertex();

	gWireframeColor = teWireframeColor[2];
    gPatchDistance = tePatchDistance[2];
    gTriDistance = vec3(0, 0, 1);
    gl_Position = gl_in[2].gl_Position;
	gLightDir = teLightDir[2];
	gVertexNormal = teNormal[2];
	gPosition = tePosition[2];
	EmitVertex();

    EndPrimitive();
}


/*
layout(triangles) in;
layout(line_strip, max_vertices = 3) out;


in vec3 passGeom_Color[3];

//out vec3 pass_Color;


void main()
{
	for(int i = 0; i < gl_in.length(); i++)
	{
		//Copy attributes
		gl_Position = gl_in[i].gl_Position;
		//pass_Color = passGeom_Color[i];

		//Done with the vertex
		EmitVertex();
	}

	EndPrimitive();
}
*/